﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;

namespace FazaDemo.BL.Services_
{
    [TestFixture]
    public class ParamsProviderTests
    {

        private List<string> _fieldInfos1;

        private List<string> _fieldInfos2;

        private List<string> _fieldInfos3;

        private ParamsProvider _provider;

        [SetUp]
        public void TestInit()
        {
            _fieldInfos1 = new List<string>
            {
                "ls.SUPPLIER_ID", 
                ";", 
                "ТСО", 
                "(спр)",
                ";", 
                "N", 
                ";", 
                "NoShowTab", 
                ";", 
                "ShowQuery", 
                ";", 
                "NoExtQuery"
            };
            _fieldInfos2 = new List<string>
            {
                "ls.KIND_OP", 
                ";", 
                "ОДН:", 
                "тип", 
                "посл.", 
                "расчета", 
                "ID", 
                ";",
                "C",
                ";",
                "NoShowTab",
                ";",
                "ShowQuery",
                ";",
                "ExtQuery"
            };
            _fieldInfos3 = new List<string>
            {
                "ls.TARGROUP_ID", 
                ";",
                "тарифная", 
                "группа", 
                "(спр)", 
                ";",
                 "N",
                 ";",
                "NoShowTab", 
                ";",
                "ShowQuery", 
                ";",
                "NoExtQuery"
            };
        }

        [SetUp]
        public void ReceiveParams()
        {
            _provider = new ParamsProvider();
        }

        [Test]
        [TestCaseSource("GetFirstParams")]
        public string GetParams_VarFieldInfos_ReturnFirstParam(List<string> fieldsInfo)
        {
            try
            {
                return _provider.GetParams(fieldsInfo)[0];
            }
            catch (Exception)
            {
                return null;
            }
        }

        [Test]
        [TestCaseSource("GetWhitespacePrecenses")]
        public bool GetParams_VarFieldInfos_ReturnWhitespacesPresence(List<string> fieldsInfo)
        {
            try
            {
                return _provider.GetParams(fieldsInfo)[1].Contains(" ");
            }
            catch (Exception)
            {
                return false;
            }
        }

        private IEnumerable<TestCaseData> GetFirstParams()
        {
            TestInit();
            yield return new TestCaseData(_fieldInfos1).Returns("ls.SUPPLIER_ID");
            yield return new TestCaseData(_fieldInfos2).Returns("ls.KIND_OP");
            yield return new TestCaseData(_fieldInfos3).Returns("ls.TARGROUP_ID");
        }

        private IEnumerable<TestCaseData> GetWhitespacePrecenses()
        {
            TestInit();
            yield return new TestCaseData(_fieldInfos1).Returns(true);
            yield return new TestCaseData(_fieldInfos2).Returns(true);
            yield return new TestCaseData(_fieldInfos3).Returns(true);
        }

    }
}
